package test.练习2;

import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class Clinet {
    public static void main(String[] args) throws Exception {
        //创建一个Socket对象，构造方法中指定服务器的IP地址和端口号
        Socket s = new Socket("127.0.0.1", 10086);

        //写出数据

        OutputStream outputStream = s.getOutputStream();
        String str = "一条数据";
        outputStream.write(str.getBytes());

        s.shutdownOutput();

        InputStreamReader isr = new InputStreamReader(s.getInputStream());

        int b;
        while ((b = isr.read()) != -1) {
            System.out.print((char)b);
        }
        //关闭资源
        s.close();
    }
}
